require "test/unit"

require "stringio"
require "Logger"
require "Tokenizer"

class TestTokenizer < Test::Unit::TestCase
  def setup
    @log = Logger.new(STDOUT)
    @log.datetime_format = "%Y-%m-%d %H:%M:%S "
    @log.level = Logger::Severity::UNKNOWN
    
    @tokenizer_tests = Dir.glob( "./test/Tokenizer/*.in")
  end
  
  def test_tokenizer
    @tokenizer_tests.each do| filename |
      filename.match('(.*)\.in')
      output = $1 + '.out'
      out_file = File.new(output)
      exp_output = ""
      s = ""
      tok = Tokenizer.new(filename, @log)
      out = StringIO.new()
      $stdout = out
      while (!(token = tok.next_token).kind_of?(EndFileToken))
        t = tok.get_token
        exp_output += out_file.readline.chomp
        print "#{t}"
      end
      assert_equal(exp_output, out.string, "Died at test #{filename}")
    end
  end
  
end
